<?php

class Create_Users_Table {

    private $tableName = 'users';
	/**
	 * Make changes to the database.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function ($tbl) {
            $tbl->increments('id');
            $tbl->integer('group_id')->unsigned();
            $tbl->string('username', 64)->unique();
            $tbl->string('password', 64);
            $tbl->string('email', 128)->unique();
            $tbl->string('hash', 64)->nullable()->default(null);
            $tbl->timestamps();

            # Foreign key
            $tbl->foreign('group_id')->references('id')->on('groups');
        });

        # Initialize data
        $initData = array(
            array(
                'id' => 1,
                'group_id' => 1,
                'username' => 'admin',
                'password' => Hash::make('p@ss'),
                'email' => 'pyttop@gmail.com'
            ),
        );
        foreach ($initData as $curData) {
            DB::table($this->tableName)->insert($curData);
        }
	}

	/**
	 * Revert the changes to the database.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop($this->tableName);
	}

}